let form=document.querySelector('form')
let errBox=document.querySelector('.error');
let nameInp=document.querySelector('.username');
let pwdInp=document.querySelector('.password');


async function fne() {
    let r=await isLogin();
    console.log(r)
    form.addEventListener('submit',async e=>{
    e.preventDefault();
    // console.log('111')
    let username=nameInp.value;
    let password=pwdInp.value;

    if(!username||!password) return alert('请完整填写表单');

    // let res = await http.post('/users/login',{username,password});
    // console.log(res)

    let {data} = await http.post('/users/login', {username,password });
    console.log({data})
    if(data.code !=1) return errBox.style.display ='block';
    errBox.style.display='none';

    localStorage.setItem('token',data.token);
    localStorage.setItem('id',data.user.id);

    alert('登录成功');
    location.href='./index.html'
})
}

fne()






























// form.addEventListener('submit',async e=>{
//     e.preventDefault();
//     // console.log('111')
//     let username=nameInp.value;
//     let password=pwdInp.value;

//     if(!username||!password) return alert('请完整填写表单');

//     // let res = await http.post('/users/login',{username,password});
//     // console.log(res)

//     let {data} = await http.post('/users/login', {username,password });
//     // console.log({data})
//     if(data.code !=1) return errBox.style.display ='block';
//     errBox.style.display='none';

//     localStorage.setItem('token',data.token);
//     localStorage.setItem('id',data.user.id);

//     alert('登录成功');
//     location.href='./index.html'
// })